<?php

namespace app\beautiful\controller\admin\member;

use app\BaseController;
use app\beautiful\model\logs\ShopBalanceLogsModel;
use app\beautiful\model\member\MemberLockModel;
use app\common\logic\DataLogic;


class FlowRealisation extends BaseController{

    /**
     * 流量变现列表
     */
    public function incomeList()

    {

        $time_type =$this->request->param('time_type/d',-1);//0今日1昨日2本周3上周4本月
        $start_time = $this->request->param('start_time');
        $end_time = $this->request->param('end_time');

        $where= [
            ['shop_id','=', $this->request->shopId],
        ];

        switch ($time_type){

            case 0:


                $start_time = date("Y-m-d H:i:s",strtotime("today"));

                $end_time = date("Y-m-d H:i:s",strtotime("today")+86399);

                break;

            case 1:

                $start_time = date('Y-m-d',mktime(0,0,0,date('m'),date('d')-1,date('Y')));

                $end_time = date("Y-m-d H:i:s",strtotime("today")-1);

                break;

            case 2:

                $start_time = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));

                $end_time = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));

                break;

            case 3:

                $start_time = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y")));

                $end_time = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));

                break;

            case 4:

                $start_time = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));

                $end_time = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));

                break;

        }


        $where[]=['add_time','between',[$start_time,$end_time]];

        $memberLockModel=MemberLockModel::with(['member'=>function($query){

            $query->field('member_id,nick_name');

        }]);
        $order=['add_time'=>'desc'];

        $field='member_lock_id,from_type,fh_money,add_time';

        $data=DataLogic::getDataList($memberLockModel,$where,$order,$field,$this->request->limit,$this->request->page,[]);

        $total_fh_money = MemberLockModel::where($where)->sum('fh_money');

        $data['total_fh_money']=sprintf("%.2f",$total_fh_money);

        return $this->success($data);

    }




}

